package cn.biplam.front.page;

import java.io.PrintWriter;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import cn.biplam.common.ajxcode.MdCode.DwTableImportFromFileCode;
import cn.biplam.common.wrapper.ErrorMessage;
import cn.biplam.common.wrapper.UserInfo;
import cn.biplam.front.component.view.mainpage.UserCall;
import cn.biplam.front.html.HtmlDiv;
import cn.biplam.front.html.HtmlInput;
import cn.biplam.front.html.HtmlPassword;
import cn.biplam.front.html.HtmlText;
import cn.biplam.front.html.HtmlValue;
import cn.biplam.front.html.base.HtmlWindow;
import cn.biplam.front.html.base.Const.Border_Style;
import cn.biplam.front.html.base.Const.Clear_Type;
import cn.biplam.front.html.base.Const.Float_Type;
import cn.biplam.front.html.base.Const.Window_Event;
import cn.biplam.front.htmlscript.script.AjxScript;
import cn.biplam.front.htmlscript.script.AjxScript.Is_SubMitData;
import cn.biplam.front.template.base.Button;
import cn.biplam.front.template.base.Input;
import cn.biplam.front.template.base.Text;
import cn.biplam.front.template.base.Input.Input_Type;
import cn.biplam.front.template.main.PageMain;

public class TestAjx {
	private HttpServletRequest request=null;
	private HttpServletResponse response=null;
	
	
	public TestAjx(HttpServletRequest request, HttpServletResponse response){
		this.request=request;
		this.response=response;
	}
	
	/**
	 * 功能：创建测试客户端页面对象
	 * @param sHomeUrl
	 * @return
	 * @throws ErrorMessage 
	 */
	private void _createPage(PageMain page,UserInfo mUser,String sHomeUrl) throws ErrorMessage{
		page.putMenu(new HtmlText(null,null,"a111111111111111111111111111111111111111111111111111111111111b"));
		
		/**目标容器*/
		page.putDomain(new HtmlDiv(null,null,"Target"));
		HtmlDiv div=new HtmlDiv("target");
		div.setBorder("1",Border_Style.Solid,"blue");
		div.setStyleSize("1024", "220");
		page.putDomain(div);
		
		/**自刷新测试内容*/
		HtmlWindow button=new Button("刷新").get();
		button.bind(Window_Event.OnClick, "r('r_test',900001);");
		page.putDomain(button);
		div = new HtmlDiv("r_test",null,"r test");
		div.setStyleSize("300","100");
		div.setFloat(Float_Type.Left);
		div.setBorder("1",Border_Style.Solid,"blue");
		HtmlValue value = new HtmlValue("r_testr",null,"999999");
		div.put(value);
		page.putDomain(div);
		
		/**菜单点击测试内容*/
		button=new Button("菜单点击").get();
		StringBuilder sb = new StringBuilder();
		sb.append(AjxScript.getPf("r_testr",
								  "900003",
								  "11",
								  "r_testr"));
//		sb.append(AjxScript.getPf("r_testr",
//									"900002",
//								  "11",
//								  "r_testr",
//								  "pr测试"));
		button.bind(Window_Event.OnClick, sb.toString());
		button.setFloat(Float_Type.Left);
		page.putDomain(button);
		/**弹出VC窗口测试*/
		div=new HtmlDiv("vctest");
		button=new Button("VC弹出").get();
		button.bind(Window_Event.OnClick, "p('vctest',130201,1,1);");
		button.setFloat(Float_Type.Left);
		div.put(button);
		div.put(new HtmlValue("vctestr",null,"1026"));
		page.putDomain(div);
		/**弹出Prompt窗口测试*/
		div=new HtmlDiv("prompttest");
		button=new Button("Prompt弹出").get();
		button.bind(Window_Event.OnClick, 
				AjxScript.getPr("prompttest", "910001", Is_SubMitData.NoSubmit, null));
		button.setFloat(Float_Type.Left);
		div.put(button);
		div.put(new HtmlValue("prompttestr",null,"1026"));
		page.putDomain(div);
		
		/**弹出窗口测试内容*/
		div=new HtmlDiv("p_test");
		div.setBorder("1", Border_Style.Solid,"blue");
		div.setStyleSize("200", "90");
		div.setFloat(Float_Type.Left);
		div.put(new Input("用户名：","username").get());
		div.put(new Input("密码：","password",Input_Type.password).get());
		button=new Button("确定").get();
		button.setClear(Clear_Type.Left);
		button.setMarginLeft("25");
		button.setMarginTop("5");
		button.bind(Window_Event.OnClick, "p('p_test','900003',1,1);");
		div.put(button);
		button=new Button("返回").get();
		button.setFloat(Float_Type.Right);
		button.setMarginRight("25");
		button.setMarginTop("5");
		div.put(button);
		div.put(new HtmlValue("p_testr",null,"900003r"));
		div.bind("ir('p_test',"+(28*7+7)+","+(8+7+2)+","+(20*7+5)+");");
		page.putDomain(div);
		
		HtmlInput sdate=new HtmlInput("sdate");
		sdate.bind(Window_Event.OnClick, "Calendar('sdate');");
		page.putDomain(sdate);
		
		HtmlWindow label2=new Text("密码:").get();
		HtmlPassword psw=new HtmlPassword(null,null,"psw");
		label2.setClear(Clear_Type.Left);
		page.putDomain(label2);
		page.putDomain(psw);
		
		page.putDomain(new Input("用户名：","username").get());
		page.putDomain(new Input("用户名：","username").get());
		page.putDomain(new Input("用户名：","username").get());
		page.putDomain(new Input("用户名：","username").get());
		
		button=new Button("上传测试").get();
		button.bind(Window_Event.OnClick, AjxScript.getPr("r_test", DwTableImportFromFileCode.Table_Import_Act, Is_SubMitData.NoSubmit,null));
		page.putDomain(button);
		
	}
	
	/**
	 * 
	 */
	public void draw(){
		String sHomeUrl=request.getContextPath();
		try {
			UserInfo mUser = new UserInfo();
			mUser.setUserID("1");
			mUser.setUserLanguage("1");
			request.getSession().setAttribute("userInfo", mUser);
			
			PageMain page = new PageMain("Ajx Test",sHomeUrl,mUser);
			page.setUserID(mUser.getUserID());
			page.putUserCall(new UserCall().get(mUser, sHomeUrl));
			this._createPage(page,mUser,sHomeUrl);
			
			/**输出*/
			this.response.setContentType("text/html"); 
			PrintWriter out = new PrintWriter (this.response.getOutputStream());
			out.println(page.get().draw());
			out.close();
		} catch (ErrorMessage e){
			e.printStackTrace();
		} catch (Exception e) {
			e.printStackTrace();
		}
	}
	
	public static void main(){
		
	}

}
